public class Solution6 {
    public String convert(String s, int numRows) {
        if (numRows==1){
            return s;
        }
        StringBuilder[] strings=new StringBuilder[numRows];
        for (int i=0;i<strings.length;i++){
            strings[i]=new StringBuilder();
        }
        int cycle=2*numRows-2;
        for (int i=0;i<s.length();i++){
            strings[numRows-1-Math.abs(numRows-1-i%cycle)].append(s.charAt(i));
        }
        StringBuilder stringBuilder=new StringBuilder();
        for (StringBuilder string : strings) {
            stringBuilder.append(string);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution6().convert("PAYPALISHIRING",3));
    }
}
